﻿using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryData;

public class MainEntity
{
    private ILazyLoader _lazyLoader;
    private List<SubEntity> _subEntities = new List<SubEntity>();

    public int Id { get; set; }
    public int Number { get; set; }

    //public virtual List<SubEntity> SubEntities { get; set; } = new();

    // 手动实现延迟加载
    public List<SubEntity> SubEntities
    {
        // get访问器调用延迟加载器加载数据
        get => _lazyLoader.Load(this, ref _subEntities);
        set => _subEntities = value;
    }

    public virtual List<SubEntity2> SubEntities2 { get; set; } = new();

    public MainEntity() { }
    // 私有构造函数供EF Core专用，对外隐藏避免误用
    private MainEntity(ILazyLoader lazyLoader) => _lazyLoader = lazyLoader;
}
